package com.example.dryyzx.dao;

import com.example.dryyzx.entity.Food;
import org.apache.ibatis.jdbc.SQL;

public class FoodSqlProvider {
    public String insertSelective(Food record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("food");
        
        if (record.getId() != null) {
            sql.VALUES("id", "#{id,jdbcType=INTEGER}");
        }
        
        if (record.getName() != null) {
            sql.VALUES("name", "#{name,jdbcType=VARCHAR}");
        }
        
        if (record.getPrice() != null) {
            sql.VALUES("price", "#{price,jdbcType=INTEGER}");
        }
        
        if (record.getType() != null) {
            sql.VALUES("type", "#{type,jdbcType=CHAR}");
        }
        
        if (record.getTag() != null) {
            sql.VALUES("tag", "#{tag,jdbcType=VARCHAR}");
        }
        
        if (record.getDay() != null) {
            sql.VALUES("day", "#{day,jdbcType=CHAR}");
        }
        
        if (record.getHalal() != null) {
            sql.VALUES("halal", "#{halal,jdbcType=BIT}");
        }
        
        if (record.getTime() != null) {
            sql.VALUES("time", "#{time,jdbcType=CHAR}");
        }
        
        if (record.getImage() != null) {
            sql.VALUES("image", "#{image,jdbcType=LONGVARBINARY}");
        }
        
        return sql.toString();
    }

    public String updateByPrimaryKeySelective(Food record) {
        SQL sql = new SQL();
        sql.UPDATE("food");
        
        if (record.getName() != null) {
            sql.SET("name = #{name,jdbcType=VARCHAR}");
        }
        
        if (record.getPrice() != null) {
            sql.SET("price = #{price,jdbcType=INTEGER}");
        }
        
        if (record.getType() != null) {
            sql.SET("type = #{type,jdbcType=CHAR}");
        }
        
        if (record.getTag() != null) {
            sql.SET("tag = #{tag,jdbcType=VARCHAR}");
        }
        
        if (record.getDay() != null) {
            sql.SET("day = #{day,jdbcType=CHAR}");
        }
        
        if (record.getHalal() != null) {
            sql.SET("halal = #{halal,jdbcType=BIT}");
        }
        
        if (record.getTime() != null) {
            sql.SET("time = #{time,jdbcType=CHAR}");
        }
        
        if (record.getImage() != null) {
            sql.SET("image = #{image,jdbcType=LONGVARBINARY}");
        }
        
        sql.WHERE("id = #{id,jdbcType=INTEGER}");
        
        return sql.toString();
    }
}